package com.si.entity;

import com.fasterxml.jackson.annotation.JsonBackReference;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @author 阿良
 * @version 1.0.0
 * @ClassName Role.java
 * @Description TODO
 * @createTime 2020年03月26日 20:21:00
 */

@Entity
@Table(name="t_role")
public class Role {


  /**
   * id
   */
  @Id
  @Basic(optional = false)
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  @Column(name = "id", nullable = false)
  private Integer id;

  /**
   * 名称
   */
  @Column(name = "name",length=100)
  private String name;

  /**
   * 编码
   */
  @Column(name = "numbers",length=100)
  private String numbers;


  /**
   * 对应菜单
   */
  @ManyToMany(cascade = CascadeType.REFRESH, fetch = FetchType.EAGER)
  @JoinTable(
          name = "sys_menu_role",//中间表名
          joinColumns = {@JoinColumn(name = "roleid")},//当前对象id在中间表的列名
          inverseJoinColumns = {@JoinColumn(name = "menuid")}//关联的另一个表在中间表的列名
  )
  private List<Menu> menuList = new ArrayList<>();


  public Integer getId() {
    return id;
  }

  public void setId(Integer id) {
    this.id = id;
  }

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public String getNumbers() {
    return numbers;
  }

  public void setNumbers(String numbers) {
    this.numbers = numbers;
  }

  public List<Menu> getMenuList() {
    return menuList;
  }

  public void setMenuList(List<Menu> menuList) {
    this.menuList = menuList;
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;
    Role role = (Role) o;
    return Objects.equals(id, role.id) &&
            Objects.equals(name, role.name) &&
            Objects.equals(numbers, role.numbers) &&
            Objects.equals(menuList, role.menuList);
  }

  @Override
  public int hashCode() {
    return Objects.hash(id, name, numbers, menuList);
  }
}

